<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="600" destroy-on-close @closed="$emit('closed')" align-center>
		<el-form :model="form" :rules="rules" :disabled="mode == 'show'" ref="dialogForm" label-width="110px" label-position="right" style="height:250px">
            <el-form-item label="处理报警" prop="FSTATUS">
                <el-radio-group v-model="form.FSTATUS" class="ml-4">
                    <el-radio label="0" size="large">未处理</el-radio>
                    <el-radio label="1" size="large">误报</el-radio>
                    <el-radio label="2" size="large">已处理</el-radio>
                    <el-radio label="3" size="large">已报修</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="处理时间" prop="date">
                <el-date-picker v-model="form.date" :value-format="'YYYY-MM-DD'"  style="width:100%" type="date" placeholder="请选择处理时间" />
            </el-form-item>
            <el-form-item label="处理方法" prop="FDES" v-if="form.FSTATUS==2">
                <el-input v-model="form.FDES" clearable></el-input>
            </el-form-item>
            <el-form-item label="处理结果" prop="result">
                <el-input v-model="form.result" type="textarea" clearable></el-input>
            </el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '处理报警',
				edit: '处理报警',
				show: '查看'
			},
			visible: false,
			isSaveing: false,
			//表单数据
			form: {
				id: "",
				FSTATUS: "",
                date:"",
                FDES:"",
                result:"",
			},
			//验证规则
			rules: {
				// ware_name: [
				// 	{ required: true, message: '请输入维修工单名称' }
				// ],
				// ware_code: [
				// 	{ required: true, message: '请输入维修工单编号' }
				// ],
			},
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = [];
					res = await this.$API.jiankong.monitorMonitor.update_status.post(this.form);
					this.isSaveing = false;
					if (res.code == 1) {
						this.$emit('success', this.form, this.mode)
						this.visible = false;
						this.$message.success(res.message)
					} else {
						this.$alert(res.message, "提示", { type: 'error' })
					}
				} else {
					return false;
				}
			})
		},
		//表单注入数据
		async setData(data) {
			this.form.id = data.id
		},
	}
}
</script>

<style></style>
